package com.itheima.shiro.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.shiro.entity.User;
import com.itheima.shiro.mapper.UserMapper;
import com.itheima.shiro.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User getUserInfoByName(String name) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("name",name);
        User user = userMapper.selectOne(wrapper);
        return user;
    }

    @Override
    public List<String> getUserRoleInfo(String principal) {
        // select name from role where id in ()
        // select rid from user_role where uid =
        // select id from user where name = #{name}
        List<String> role = userMapper.getUserRoleInfoMapper(principal);
        return role;
    }

    @Override
    public List<String> getUserPermissionInfo(List<String> roles) {
        // select info from permissions where id in()
        // select pid from role_ps where rid in ()
        // select id from role where name in ()
        return userMapper.getUserPermissionsInfoMapper(roles);
    }
}
